package com.zsc.wxm.ysh.anjo.utils;

import cn.hutool.core.date.DateUtil;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;

/**
 * 描述：日期
 *
 * @author playmaker
 * @since 2021/2/24 21:12
 */
public class MyDateUtil {

    private static final String FORMAT = "yyyy-MM-dd hh:mm:ss";

    /**
     * 获取当天的开始日期
     *
     * @param date
     * @return 2021-02-24 21:15:25 --> 2021-02-24 00:00:00
     * @throws ParseException
     */
    public static Date getBeginDate(Date date) throws ParseException {
        String now = DateUtil.format(date, FORMAT);
        String[] s = now.split(" ");
        SimpleDateFormat f = new SimpleDateFormat(FORMAT);
        return f.parse(s[0] + " " + "00:00:00");
    }


    /**
     * 获取当天结束日期
     *
     * @param date
     * @return 2021-02-24 21:15:25 --> 2021-02-24 23:59:59
     * @throws ParseException
     */
    public static Date getOverDate(Date date) throws ParseException {
        String now = DateUtil.format(date, FORMAT);
        String[] s = now.split(" ");
        SimpleDateFormat f = new SimpleDateFormat(FORMAT);
        return f.parse(s[0] + " " + "23:59:59");
    }

    /**
     * LocalDateTime 转 String  yyyy-MM-dd HH:mm:ss
     *
     * @param time LocalDateTime
     * @return String
     */
    public static String getLocalDateTimeStr(LocalDateTime time) {
        DateTimeFormatter fmt24 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        return time.format(fmt24);
    }

    /**
     * LocalDateTime 转 String yyyy-MM-dd
     *
     * @param time LocalDateTime
     * @return String
     */
    public static String getLocalDateTimeYYMMDDStr(LocalDateTime time) {
        DateTimeFormatter fmt = DateTimeFormatter.ISO_LOCAL_DATE;
        return time.format(fmt);
    }





}
